/**
 * 
 * @author pijun
 *
 * basic gui for the calendar system.
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.MalformedURLException;

public class Gui extends JFrame
{
	private static final int WIDTH = 800;
	private static final int HEIGHT = 600;
	
	private JLabel  commentL, geo1L, geo2L, locationL, resourceL, Start1L,Start2L,Start3L,Start4L,Start5L,Start6L,
	end1L, end2L,end3L,end4L,end5L,end6L,tzidL;
	private JTextField  commentTF, geo1TF, geo2TF, locationTF, resourceTF, Start1TF,Start2TF,Start3TF,Start4TF,Start5TF,Start6TF, 
	end1TF,end2TF,end3TF,end4TF,end5TF,end6TF, tzidTF;
	private JButton  exitB, submit;
	public String[] textfield = new String[7];
	
	//Buttons:
	private ExitButtonHandler ebHandler;
	private SubmitButtonHandler SbHandler;
	
	
	public Gui()
	{
		//labels for each of the text fields
		commentL = new JLabel("Enter comments:", SwingConstants.RIGHT);
		geo1L = new JLabel("Enter the lattitude:", SwingConstants.RIGHT);
		geo2L = new JLabel("Enter the logitude:", SwingConstants.RIGHT);
		locationL = new JLabel("Enter the location:", SwingConstants.RIGHT);
		resourceL = new JLabel("Enter the resources:", SwingConstants.RIGHT);
		Start1L = new JLabel("Enter the Start Month: ", SwingConstants.RIGHT);
		Start2L = new JLabel("Enter the Start Day: ", SwingConstants.RIGHT);
		Start3L = new JLabel("Enter the Start Year: ", SwingConstants.RIGHT);
		Start4L = new JLabel("Enter the Start Hour: ", SwingConstants.RIGHT);
		Start5L = new JLabel("Enter the Start Minute: ", SwingConstants.RIGHT);
		Start6L = new JLabel("Enter the Start Second: ", SwingConstants.RIGHT);
		end1L = new JLabel("Enter the end Month:", SwingConstants.RIGHT);
		end2L = new JLabel("Enter the end Day:", SwingConstants.RIGHT);
		end3L = new JLabel("Enter the end Year:", SwingConstants.RIGHT);
		end4L = new JLabel("Enter the end Hour:", SwingConstants.RIGHT);
		end5L = new JLabel("Enter the end Minute:", SwingConstants.RIGHT);
		end6L = new JLabel("Enter the end Second:", SwingConstants.RIGHT);
		tzidL = new JLabel("Enter the timezone:", SwingConstants.RIGHT);
				
		//text fields
		
		commentTF = new JTextField(10);
		geo1TF = new JTextField(10);
		geo2TF = new JTextField(10);
		locationTF = new JTextField(10);
		resourceTF = new JTextField(10);
		Start1TF = new JTextField(10);
		Start2TF = new JTextField(10);
		Start3TF = new JTextField(10);
		Start4TF = new JTextField(10);
		Start5TF = new JTextField(10);
		Start6TF = new JTextField(10);
		end1TF = new JTextField(10);
		end2TF = new JTextField(10);
		end3TF = new JTextField(10);
		end4TF = new JTextField(10);
		end5TF = new JTextField(10);
		end6TF = new JTextField(10);
		tzidTF = new JTextField(10);
		
		
		//SPecify handlers for each button and add (register) ActionListeners to each button.
		//exit button handler
		exitB = new JButton("Exit");
		ebHandler = new ExitButtonHandler();
		exitB.addActionListener(ebHandler);
		
		//submit button handler
		submit = new JButton("Submit");
		SbHandler = new SubmitButtonHandler();
		submit.addActionListener(SbHandler);
		
		
		setTitle("Event Creator");
		Container pane = getContentPane();
		pane.setLayout(new GridLayout(10, 4));
		
		//Add things to the pane in the order you want them to appear (left to right, top to bottom)
		pane.add(commentL);
		pane.add(commentTF);
		pane.add(geo1L);
		pane.add(geo1TF);
		pane.add(geo2L);
		pane.add(geo2TF);
		pane.add(locationL);
		pane.add(locationTF);
		pane.add(resourceL);
		pane.add(resourceTF);
		pane.add(Start1L);
		pane.add(Start1TF);
		pane.add(Start2L);
		pane.add(Start2TF);
		pane.add(Start3L);
		pane.add(Start3TF);
		pane.add(Start4L);
		pane.add(Start4TF);
		pane.add(Start5L);
		pane.add(Start5TF);
		pane.add(Start6L);
		pane.add(Start6TF);
		pane.add(end1L);
		pane.add(end1TF);
		pane.add(end2L);
		pane.add(end2TF);
		pane.add(end3L);
		pane.add(end3TF);
		pane.add(end4L);
		pane.add(end4TF);
		pane.add(end5L);
		pane.add(end5TF);
		pane.add(end6L);
		pane.add(end6TF);
		pane.add(tzidL);
		pane.add(tzidTF);
		pane.add(exitB);
		pane.add(submit);
		
		setSize(WIDTH, HEIGHT);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	public class ExitButtonHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}
	
	public class SubmitButtonHandler implements ActionListener{
		public void actionPerformed(ActionEvent e){
			//puts all the users data into an array
			String[] array;
			array = new String[18];
			array[0] = commentTF.getText();
			array[1] = geo1TF.getText();
			array[2] = geo2TF.getText();
			array[3] = locationTF.getText();
			array[4] = resourceTF.getText();
			array[5] = Start1TF.getText();
			array[6] = Start2TF.getText();
			array[7] = Start3TF.getText();
			array[8] = Start4TF.getText();
			array[9] = Start5TF.getText();
			array[10] = Start6TF.getText();
			array[11] = end1TF.getText();
			array[12] = end2TF.getText();
			array[13] = end3TF.getText();
			array[14] = end4TF.getText();
			array[15] = end5TF.getText();
			array[16] = end6TF.getText();
			array[17] = tzidTF.getText();
			
			Creation export = new Creation(); //test object
			
			export.classification(0); //sets classification to PUBLIC
			export.timeZoneId(array[17]);
			export.comment(array[0]); //sets a comment
			export.resources(array[4]);
			export.geoPosition(Integer.parseInt(array[1]), Integer.parseInt(array[2]));
			try {
				export.location(array[3], null);
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			export.dtStart(Integer.parseInt(array[5]), Integer.parseInt(array[6]), Integer.parseInt(array[7]), Integer.parseInt(array[8]), Integer.parseInt(array[9]), Integer.parseInt(array[10]));
			export.dtEnd(Integer.parseInt(array[11]), Integer.parseInt(array[12]), Integer.parseInt(array[13]), Integer.parseInt(array[14]), Integer.parseInt(array[15]), Integer.parseInt(array[16]));
			export.dtStamp();
			try {
				export.createFile();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} //tests createFile() method
		}
	}
	
	public static void main(String[] args)
	{
		Gui rectObj = new Gui();
	}
	
}